import os
from elasticsearch import Elasticsearch



es = Elasticsearch(
    "http://localhost:9200",
    timeout=3600
)


print(es.info())
es.indices.create(index="test")
es.index(index="test", id=2, body={"id": "2", "name": "小小明"})
es.index(index="test", id=3, body={"id": "3", "name": "小红"})


#print(es.get(index="test", id='1'))
result = es.search(index="test", query={"match": {"name": "明"}}, size=2)
for hit in result["hits"]["hits"]:
    print(hit["_score"], hit["_source"])
